Doesn't [UIWindow addSubView:] retain?
Posted
by Dan Ray
on Stack Overflow
See other posts from Stack Overflow
or by Dan Ray
Published on 2010-05-20T12:46:58Z
Indexed on
2010/05/20
12:50 UTC
Read the original article
Hit count: 503
iphone
|cocoa-touch
Check it:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSLog(@"Checking login--user value is %@", [defaults valueForKey:@"userID"]);
if ([defaults valueForKey:@"userID"] == NULL){
LoginViewController *loginController = [[LoginViewController alloc] initWithNibName:@"LoginView" bundle:nil];
[window addSubview:loginController.view];
[loginController release];
}
else {
[window addSubview:[navigationController view]];
}
Every other place when I put a subview into another view, I release that view after I've done that, because it's now owned by the view it's a subview of. HERE, though, when I do [loginController release]
, every IBAction on that loginController gets called against a deallocated instance. Commenting out that line makes everything work.
I note the difference in approach between my loginController and the navigationController that came with the template; the navigationController is a synthesized property that gets released in -(void)dealloc{ }
, so it's still around after being put into window
.
© Stack Overflow or respective owner